/*****************************************************************************
 * plum_fsm_service.c
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

/*****************************************************************************
 * Included Files
 ****************************************************************************/
#include "plum_api.h"
/*****************************************************************************
 * Trace Definitions
 ****************************************************************************/
#define LOG_RUN_LEVEL LOG_LEVEL_DEBUG
#define LOG_MODULE    "fsm.service"
/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Private Types
 ****************************************************************************/

/*****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/*****************************************************************************
 * Private Data
 ****************************************************************************/

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/*****************************************************************************
 * Private Functions
 ****************************************************************************/

/*****************************************************************************
 * Public Functions
 ****************************************************************************/

PLUM_PUBLIC
plum_s32 plum_cal_fsm_srv_call(plum_s8 *dev_name, plum_u32 srv_id,
                               plum_s8 **argv)
{
    plum_s32 rc = PLUM_ECODE_INVALID;

    plum_u32 loop;
    for (loop = 0;
         loop < PLUM_SECTION_ITEM_COUNT(PLUM_SERVICE_SECTION, plum_fsm_srv_t);
         loop++) {
        plum_fsm_srv_t *item =
            PLUM_SECTION_ITEM_GET(PLUM_SERVICE_SECTION, plum_fsm_srv_t, loop);
        if (memcmp(item->dev_name, dev_name, strlen((char *)item->dev_name)) ==
            0) {
            LOG_I("find the %s serice :%d,do it", dev_name, srv_id);
            rc = item->service_handler(srv_id, argv);
        }
    }

    return (rc);
}

PLUM_PUBLIC
plum_s32 plum_cal_fsm_srv_info(plum_s8 *dev_name)
{
    plum_s32 rc = PLUM_ECODE_INVALID;

    plum_u32 loop;
    for (loop = 0;
         loop < PLUM_SECTION_ITEM_COUNT(PLUM_SERVICE_SECTION, plum_fsm_srv_t);
         loop++) {
        plum_fsm_srv_t *item =
            PLUM_SECTION_ITEM_GET(PLUM_SERVICE_SECTION, plum_fsm_srv_t, loop);
        if (memcmp(item->dev_name, dev_name, strlen((char *)item->dev_name)) ==
            0) {
            LOG_I("find the %s ", dev_name);
            rc = item->info();
        }
    }

    return (rc);
}

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
